﻿using LibNiconico.NiconicoApi.Internal;
using LibNiconico.NiconicoApi.Utils;
using LibNiconico.NiconicoApi.Videos.Constant;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace LibNiconico.NiconicoApi.Mylist
{
    /// <summary>
    /// マイリストAPIヘルパー
    /// </summary>
    public class NicoMylistApiHelper:NicoApiHelperBase
    {
        internal NicoMylistApiHelper(NiconicoAuth auth, NiconicoApiInfoGetCreateInfo createInfo) : base(auth, createInfo) { }


        /// <summary>
        /// マイリスト追加リクエスト
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<NicoMylistAddRequestResponse> AddMylistRequestAsync(string id)
        {

            return await this.AddMylistRequestAsync(new NicoMylistAddRequestQueryInfo(id)).ConfigureAwait(false);
        }

        /// <summary>
        /// マイリスト追加リクエスト
        /// </summary>
        /// <param name="queryInfo"></param>
        /// <returns></returns>
        internal async Task<NicoMylistAddRequestResponse> AddMylistRequestAsync(NicoMylistAddRequestQueryInfo queryInfo)
        {
            using (var api = new NiconicoInfoGetApiHtmlImpl(NicoVideoConstant.NICOVIDEO_URL, CreateMostLoginApiHttpClient()))
            {
                return NicoMylistAddRequestResponse.Parse((await api.GetAsync(queryInfo).ConfigureAwait(false)).Content);
            }
        }

        /// <summary>
        /// マイリスト追加実行
        /// </summary>
        /// <param name="selectMylistItem"></param>
        /// <param name="requestResponse"></param>
        /// <returns></returns>
        public async Task<NicoMylistAddExecuteResponse> AddMylistExecuteAsync(NicoMylistItem selectMylistItem, NicoMylistAddRequestResponse requestResponse)
        {
            return await AddMylistExecuteAsync(new NicoMylistAddExecuteQueryInfo(selectMylistItem, requestResponse)).ConfigureAwait(false);
        }

        /// <summary>
        /// マイリスト追加実行
        /// </summary>
        /// <param name="queryInfo"></param>
        /// <returns></returns>
        internal async Task<NicoMylistAddExecuteResponse> AddMylistExecuteAsync(NicoMylistAddExecuteQueryInfo queryInfo)
        {
            using (var api = new NiconicoInfoGetApiJsonImpl(NicoVideoConstant.NICOVIDEO_URL, CreateMostLoginApiHttpClient()))
            {
                return  NicoMylistAddExecuteResponse.Parse(( await api.PostAsync(queryInfo).ConfigureAwait(false)).Content);
            }
        }

    }
}
